home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 7.1 KB | 297 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ToolFacet.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef TOOLFACET_H
- #include "ToolFacet.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWSELECTION_H
- #include "DrawSelection.h"
- #endif
-
- #ifndef SHAPES_H
- #include "Shapes.h"
- #endif
-
- #ifndef DRAWFRAME_H
- #include "DrawFrame.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- // ----- Graphix Includes -----
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __EVENTS__
- #include <Events.h> // GetMouse, StillDown.
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h> // HiWord etc.
- #endif
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STDLIB__
- #include <StdLib.h> // Abs
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h> // See MoveTransformBy
- #endif
-
- #pragma segment drawpart
-
- //=========================================================================
- // CToolFacet
- //=========================================================================
-
- //------------------------------------------------------------------------------
- // CToolFacet::CToolFacet
- //------------------------------------------------------------------------------
-
- CToolFacet::CToolFacet()
- {
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::InitToolFacet
- //------------------------------------------------------------------------------
-
- void CToolFacet::InitToolFacet(XMPFacet* xmpFacet, CDrawPart* drawPart)
- {
- InitFacet(xmpFacet);
- fDrawPart = drawPart;
-
- fRects[0].Set(ff(2), ff(2), ff(24), ff(24));
- fRects[1].Set(ff(23), ff(2), ff(45), ff(24));
-
- fRects[2].Set(ff(2), ff(23), ff(24), ff(45));
- fRects[3].Set(ff(23), ff(23), ff(45), ff(45));
-
- fRects[4].Set(ff(2), ff(44), ff(24), ff(66));
- fRects[5].Set(ff(23), ff(44), ff(45), ff(66));
-
- fRects[6].Set(ff(2), ff(69), ff(17), ff(81));
- fRects[7].Set(ff(16), ff(69), ff(31), ff(81));
- fRects[8].Set(ff(30), ff(69), ff(45), ff(81));
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::~CToolFacet
- //------------------------------------------------------------------------------
-
- CToolFacet::~CToolFacet()
- {
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::Draw
- //------------------------------------------------------------------------------
-
- void CToolFacet::Draw(FW_CGraphicContext *gc)
- {
- FW_UNUSED(gc);
-
- DrawTools(gc);
- DrawColors(gc);
-
- FW_CColor black(FW_kRGBBlack);
- ::RGBForeColor(&(RGBColor)black); // temporary
-
- FW_CAcquireASLMResourceAccess aq;
-
- FW_SPlatformRect r;
- PicHandle hPic = ::GetPicture(131);
- ::SetRect(&r, 2, 2 + kToolHeight + 3, kToolWidth + 2, 2 + kToolHeight + 3 + kSelectorHeight);
- ::DrawPicture(hPic, &r);
-
- DrawFillFrame(fDrawPart->GetFillFrame(), FW_kBlackPat);
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::DrawTools
- //------------------------------------------------------------------------------
-
- void CToolFacet::DrawTools(FW_CGraphicContext *gc)
- {
- FW_UNUSED(gc);
-
- FW_CAcquireASLMResourceAccess aq;
-
- FW_SPlatformRect r;
- ::SetRect(&r, 2, 2, kToolWidth + 2, kToolHeight + 2);
- PicHandle hPic = ::GetPicture(128 + fDrawPart->GetFillFrame() - 1);
- ::DrawPicture(hPic, &r);
-
- InvertTool(gc, fDrawPart->GetTool());
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::DrawColors
- //------------------------------------------------------------------------------
-
- void CToolFacet::DrawColors(FW_CGraphicContext *gc)
- {
- XMPCoordinate left = 5;
- XMPCoordinate top = kToolsWindowHeight - kColorSelectorHeight - 5;
- FW_CRect colorRect(ff(left), ff(top), ff(left + kColorSelectorWidth), ff(top + kColorSelectorHeight));
-
- FW_CColor color;
-
- FW_CRectShape rectShape(colorRect);
-
- fDrawPart->GetFillColor(&color);
- rectShape->SetForeColor(color);
- rectShape->SetPenSize(ff(5));
- rectShape->Draw(gc); // fill
-
- fDrawPart->GetPenColor(&color);
- rectShape->SetForeColor(color);
- rectShape->SetShapeFill(FW_kFramed);
- rectShape->Draw(gc); // frame
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::DoMouseDown
- //------------------------------------------------------------------------------
-
- FW_Boolean CToolFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
- {
- FW_UNUSED(event);
-
- for (short i = 0; i < kNbRects; i++)
- {
- if (fRects[i].Contains(where))
- {
- if (i<=5)
- fDrawPart->SetTool(kSelectTool + i);
- else
- fDrawPart->SetFillFrame(i-5);
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::CheckTool
- //------------------------------------------------------------------------------
-
- void CToolFacet::CheckTool(unsigned short oldTool, unsigned short newTool)
- {
- FW_CGraphicContext i(*this);
- InvertTool(&i, oldTool);
- InvertTool(&i, newTool);
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::InvertTool
- //------------------------------------------------------------------------------
-
- void CToolFacet::InvertTool(FW_CGraphicContext* gc, unsigned short theTool)
- {
- FW_UNUSED(gc);
-
- if (theTool>0)
- {
- FW_SPlatformRect rect;
- fRects[theTool -1].AsPlatformRect(rect);
- ::InsetRect(&rect, 1, 1);
- ::InvertRect(&rect);
- }
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::CheckFillFrame
- //------------------------------------------------------------------------------
-
- void CToolFacet::CheckFillFrame(unsigned short oldFillFrame, unsigned short newFillFrame)
- {
- FW_CGraphicContext i(*this);
- DrawFillFrame(oldFillFrame, FW_kWhitePat);
- DrawFillFrame(newFillFrame, FW_kBlackPat);
- DrawTools(&i);
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::DrawFillFrame
- //------------------------------------------------------------------------------
-
- void CToolFacet::DrawFillFrame(unsigned short fillFrame, const FW_CPattern& pattern)
- {
- if (fillFrame>0)
- {
- FW_SPlatformRect rect;
- fRects[5 + fillFrame].AsPlatformRect(rect);
- ::InsetRect(&rect, 1, 1);
- ::OffsetRect(&rect, 0, 2);
- ::PenPat(pattern);
- ::PenSize(2, 2);
- ::MoveTo(rect.left, rect.bottom);
- ::LineTo(rect.right - 2, rect.bottom);
- }
- }
-
- //------------------------------------------------------------------------------
- // CToolFacet::UpdateColors
- //------------------------------------------------------------------------------
-
- void CToolFacet::UpdateColors()
- {
- FW_CGraphicContext gc(*this);
-
- DrawColors(&gc);
- }
-